<template>
  <div class="box">
    <div class="title">
      <p>未来七天游客数量趋势图</p>
      <img src="../../images/dataScreen-title.png" alt="" />
    </div>
    <div class="charts" ref="charts"></div>
  </div>
</template>

<script setup lang="ts" name="Line">
// 1.引入echarts
import * as echarts from 'echarts'
import { onMounted, ref } from 'vue'

// 2.获取DOM元素
let charts = ref()

onMounted(() => {
  // 3.初始化实例对象
  let myCharts = echarts.init(charts.value)
  // 4.设置echarts配置项
  myCharts.setOption({
    // 标题组件
    /* title: {
      text: '游客数量趋势图',
      left: 'center',
      top: '0px',
    }, */
    // 提示信息
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        label: {
          backgroundColor: 'skyblue',
          fontSize: 15,
        },
        crossStyle:{
          color: 'skyblue',
        },
        lineStyle:{
          color: 'skyblue',
        }
      },
      textStyle: {
        fontSize: 15,
      },
      backgroundColor:"aqua"
    },
    // x|y轴组件
    xAxis: {
      type: 'category', // 均匀分布
      boundaryGap: false, // x轴两侧不留白
      // x轴的数据
      data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
      //取消分割线
      splitLine: {
        show: false,
      },
      // 刻度设置
      axisTick: {
        show: true,
      },
      // 标签设置
      axisLabel: {
        color: 'white',
        fontSize: 16,
      },
    },
    yAxis: {
      type: 'value',
      //取消分割线
      splitLine: {
        show: false,
      },
      // 坐标线设置
      axisLine: {
        show: true,
        lineStyle: {
          width: 2,
        },
      },
      // 刻度设置
      axisTick: {
        show: true,
      },
      // 标签设置
      axisLabel: {
        color: 'white',
        fontSize: 14,
      },
    },
    series: [
      {
        type: 'line',
        data: [350, 630, 424, 718, 535, 847, 900],
        smooth: true, // 折线是否平滑
        emphasis: {
          focus: 'series',
        },
        // 区域填充样式
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 0,
                color: 'red', // 0% 处的颜色
              },
              {
                offset: 1,
                color: 'blue', // 100% 处的颜色
              },
            ],
            global: false, // 缺省为 false
          },
        },
      },
    ],
    grid: {
      left: 40,
      right: 20,
      top: 20,
      bottom: 45,
    },
  })
})
</script>

<style scoped lang="scss">
.box {
  width: 100%;
  height: 100%;
  background: url(../../images/dataScreen-main-cb.png) no-repeat;
  background-size: 100% 100%;
  .title {
    margin-left: 10px;
    p {
      color: white;
      font-size: 20px;
    }
  }
  .charts {
   height: calc(100% - 40px);
  }
}
</style>
